<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
    <title>Document</title>
    <style>
        body{
            height:2000px;
        }
        *{margin:0;padding:0px;}
        .nav{
            width:100%;
            height:50px;line-height:50px;text-align:center;
            background:#00bcd4;
            position:fixed;
        }
    </style>
</head>
    <body>
        <!-- 当我的窗口距离顶部达到200px，我就让nav完全显示 -->
        <div class="nav">
            导航
        </div>
        <script>
            $(window).scroll(function(){
                // 获取滚动条距离顶部的距离
                var scrollTop=$(window).scrollTop();
                // console.log(scrollTop)
                var opacity=scrollTop/300;
                // console.log(opacity)
                if(opacity>1){
                    opacity=1
                }
                $(".nav").css({opacity:opacity})
            })
        </script>
    
</body>
</html>